package com.wx.service.user.service.impl;

import com.wx.service.accesstoken.service.IAccessTokenService;
import com.wx.service.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Service
public class UserServiceImpl implements IUserService {

  @Value("${wx.user.getUserByCode}")
  private String getUserByCodeUrl;

  @Autowired
  private RestTemplate restTemplate;

  @Autowired
  private IAccessTokenService accessTokenService;

  @Override
  public Map getUserByCode(String code) {
    String accessToken = accessTokenService.getAccessToken();
    String url = getUserByCodeUrl.replace("{accessToken}", accessToken).replace("{code}", code);
    Map user = restTemplate.getForObject(url, Map.class);
    return user;
  }
}
